<?php

require_once('mysql_table.php');

class cliente extends mysql_table {

  function __construct() {
    parent::__construct();
    $this->TableName = "CLIENTES";
    $this->IDField = "ID";

    $this->fields['ID'] = "";
    $this->fields['NOMBRE'] = "";
    $this->fields['APELLIDO'] = "";
    $this->fields['ID_EMPRESA'] = "";
    $this->fields['ID_EDIFICIO'] = "";
    $this->fields['TELEFONO'] = "";
    $this->fields['TELEFONO2'] = "";
    $this->fields['MAIL'] = "";
    $this->fields['DIA_CUMPLE'] = "";
    $this->fields['MES_CUMPLE'] = "";
    $this->fields['CLAVE'] = "";
    $this->fields['DESEA_MAILS'] = "";
    $this->fields['ID_STATUS'] = "";
  }

  /**
   * @return 1 y llena el objeto si lo encuentra
   * @example para el logueo
   * */
  function buscar_logueo($usuario, $clave) {

    $query = "SELECT * FROM " . $this->TableName . " WHERE MAIL='" . $usuario . "' AND CLAVE='" . $clave . "' AND ID_STATUS=1";
    $resource = $this->runquery($query);
    //print_r($query);
    if ($resource) {
      if (mysql_num_rows($resource) > 0) {
        $this->getdata($resource);
        return 1;
      } else {
        return 0;
      }
    }
  }
  
  /**
   * @return 1 y llena el objeto si lo encuentra
   * @example para el logueo
   * */
  function buscar_logueo_2($usuario, $clave) {

    $query = "SELECT * FROM " . $this->TableName . " WHERE MAIL='" . $usuario . "' AND CLAVE='" . $clave . "' AND ID_STATUS=2";
    $resource = $this->runquery($query);
    //print_r($query);
    if ($resource) {
      if (mysql_num_rows($resource) > 0) {
        $this->getdata($resource);
        return 1;
      } else {
        return 0;
      }
    }
  }

  /**
   * @return 1 y llena el objeto si lo encuentra
   * @example para crear el cliente
   * */
  function buscar_mail($mail) {

    $query = "SELECT * FROM " . $this->TableName . " WHERE MAIL='" . $mail . "' AND ID_STATUS != 0";
    $resource = $this->runquery($query);
    //print_r($query);
    if ($resource) {
      if (mysql_num_rows($resource) > 0) {
        $this->getdata($resource);
        return 1;
      } else {
        return 0;
      }
    }
  }

  /**
   * @return todos los proveedores activos
   * @example para listarlos
   * */
  function buscar() {

    $query = "SELECT * FROM CLIENTES WHERE ID_STATUS = 1";
    $salida = $this->tovector_assoc_query($query);
    //print($query);
    return $salida;
  }

}

?>
